package conf

import (
	"fmt"
	"github.com/spf13/viper"
)

var (
	Config *Settings
)

type Settings struct {
	Application *Application `yaml:"application"`
	Database    *Database    `yaml:"database"`
	File        *File        `yaml:"file"`
}

type Application struct {
	Mode         string `yaml:"mode"`
	Host         string `yaml:"host"`
	Name         string `yaml:"name"`
	Port         int    `yaml:"port"`
	ReadTimeout  int    `yaml:"readtimeout"`
	WriteTimeout int    `yaml:"writetimeout"`
}

type Database struct {
	Driver string `yaml:"driver"`
	Source string `yaml:"source"`
}

type File struct {
	Log        string `yaml:"log"`
	UploadPath string `yaml:"uploadpath"`
}

func InitConfigByViper() {
	// var _config *conf.Settings
	viper.SetConfigType("yaml")
	viper.SetConfigFile("./conf/settings.yml")

	err := viper.ReadInConfig()
	if err != nil {
		fmt.Println(err.Error())
	}
	err = viper.Unmarshal(&Config)
	if err != nil {
		fmt.Println(err.Error())
	}

	fmt.Printf("config.Application: %#v\n", Config.Application)
	fmt.Printf("config.Databases: %#v\n", Config.Database)
	fmt.Printf("config.File: %#v\n", Config.File)

}
